package 数组;

import java.util.Arrays;

public class 旋转数组 {
    public static void main(String[] args) {
        旋转数组 test = new 旋转数组();
        int[] nums = {1,2,3,4,5,6,7};
        //int[] nums = {1, 2};
        test.rotate(nums, 3);
    }

    public void rotate(int[] nums, int k) {
        int kmod = k % nums.length;
        int[] ints = Arrays.copyOf(nums, nums.length);
        for (int i = nums.length - kmod; i < nums.length; i++) {
            nums[(i + kmod) % nums.length] = ints[i];
        }
        for (int i = 0; i < nums.length - kmod; i++) {
            nums[i + kmod] = ints[i];
        }
    }
}
